<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Upload_model extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
	} 
	
	// Category                 
	function get_list($num=20, $offset=0)
	{
		$this->db->where('bl_active !=',-1);
		$this->db->order_by('dt_create','desc');
		$query = $this->db->get('lienhe_upload',$num,$offset);
		return $query->result();
	}
	
	function count_list()
	{
		$this->db->where('bl_active !=',-1);
		$query = $this->db->get('lienhe_upload');
		return $query->num_rows();
	}
	
	function set_view($id)
	{
		$data = array(
			'is_read' => 1
		);
		$this->db->where('id',$id);
		$this->db->update('lienhe_upload',$data) ;
	}
	
	function getlienhe($id=0)
	{ 
		if(!empty($id)) $this->db->where('id',$id);
		$query = $this->db->get('lienhe_upload');
		return $query->row();
	}
	
	function delete($id)
	{
		$data = array(
			'bl_active' 	=> -1
		);
		$this->db->where('id',$id);
		$this->db->update('lienhe_upload',$data) ;
	}
	
	function remove()
	{
		$date = new DateTime();
		$date->modify('-3 month');
		$date_del = $date->format('Y-m-d H:i:s');
		
		$this->db->where('bl_active', -1);
		$this->db->where('dt_create <', $date_del);
		if($this->db->delete('lienhe_upload')){
		  	return true;
		}else{
		  	return false;
		}
	}
}
?>
